********************************************************************************
*Project:  	Swiss Trade During the Covid-19 Pandemic: An Early Appraisal	
*Authors:	KB, SL, VP, PW											
*This File: Clean Trade Data
*Version: 	vFinal						
*Date: 		2020-09-01						
********************************************************************************

********************************************************************************
*1. Import Data
********************************************************************************

*Export Trade Data 1997--2020, Handelspartner (SEASONALLY ADJUSTED)
import delimited "${root}\data\FCA_Monthly_Data\SEHM.csv",						///
delimiter(";") asdouble clear 
duplicates tag _all, gen(dup)
assert dup==0
drop dup
saveold "${root}\temp\raw_1997_2020_Mexporte_HP.dta", replace version(13)

*Import Trade Data 1997--2020, Handelspartner (SEASONALLY ADJUSTED)
import delimited "${root}\data\FCA_Monthly_Data\SIHM.csv",						///
delimiter(";") asdouble clear 
duplicates tag _all, gen(dup)
assert dup==0
drop dup
saveold "${root}\temp\raw_1997_2020_Mimporte_HP.dta", replace version(13)

*Export Trade Data 1997--2020, ALL Handelspartner (ONLY NOMINAL VALUES)
import delimited "${root}\data\FCA_Monthly_Data\SEHM_FULL.csv",					///
delimiter(";") asdouble clear 
duplicates tag _all, gen(dup)
assert dup==0
drop dup
saveold "${root}\temp\raw_1997_2020_Mexporte_HP_FULL.dta", replace version(13)

*Import Trade Data 1997--2020, ALL Handelspartner (ONLY NOMINAL VALUES)
import delimited "${root}\data\FCA_Monthly_Data\SIHM_FULL.csv",					///
delimiter(";") asdouble clear 
duplicates tag _all, gen(dup)
assert dup==0
drop dup
saveold "${root}\temp\raw_1997_2020_Mimporte_HP_FULL.dta", replace version(13)


*Export Trade Data 1997--2020, Warenart
import delimited "${root}\data\FCA_Monthly_Data\SEWM.csv",						///
delimiter(";") asdouble clear 
duplicates tag _all, gen(dup)
assert dup==0
drop dup
saveold "${root}\temp\raw_1997_2020_Mexporte_WA.dta", replace version(13)

*Import Trade Data 1997--2020, Warenart
import delimited "${root}\data\FCA_Monthly_Data\SIWM.csv",						///
delimiter(";") asdouble clear 
duplicates tag _all, gen(dup)
assert dup==0
drop dup
saveold "${root}\temp\raw_1997_2020_Mimporte_WA.dta", replace version(13)


*APPEND TRADE DATA BY COUNTRY
clear
append using "${root}\temp\raw_1997_2020_Mexporte_HP.dta"
generate handel_typ="E"
append using "${root}\temp\raw_1997_2020_Mimporte_HP.dta"
replace handel_typ="I" if handel_typ==""
saveold "${root}\temp\HP_season.dta", replace version(13)

keep hp jahr periode handel_typ
duplicates drop _all, force
saveold "${root}\temp\sample_HP_season.dta", replace version(13)

clear
append using "${root}\temp\raw_1997_2020_Mexporte_HP_FULL.dta"
generate handel_typ="E"
append using "${root}\temp\raw_1997_2020_Mimporte_HP_FULL.dta"
replace handel_typ="I" if handel_typ==""
drop if hp=="tot"
destring hp, replace

merge 1:1 jahr periode hp handel_typ using "${root}\temp\sample_HP_season.dta"
keep if _merge==1
drop _merge
split w, parse(",")
drop w2 w
rename w1 w
destring w, replace
saveold "${root}\temp\HP_season_FULL.dta", replace version(13)

append using "${root}\temp\HP_season.dta"


foreach var in w wa ws wt { 
	format `var' %16.2f
}

rename periode monat
rename hp land_id
rename w handel_chf
rename wa handel_chf_a
rename ws handel_chf_s
rename wt handel_chf_t

*Merge Länder Labels
merge m:1 land_id using "${root}\temp\codes_land.dta"
drop if _merge==2 

rename _merge MERGE_1

merge m:1 land_id using "${root}\temp\codes_HP_SECO.dta", keepusing(land_iso2_SECO)
drop if _merge==2 

drop if MERGE_1==1 & land_iso2_SECO=="XXX"
drop if MERGE_1==1 & land_iso2_SECO=="" & land_id>10000

assert MERGE_1==3
drop land_iso2_SECO _merge
rename MERGE_1 _merge

replace land_iso2="zzna" if _merge==1
replace land_str="zzna: UNKNOWN" if _merge==1  
drop _merge 

replace land_iso2="EU" if land_id==100302
replace land_str="Europäische Union (source:FCA)" if land_id==100302

replace land_iso2="EURO" if land_id==100305	
replace land_str="Eurozone (source:FCA)" if land_id==100305	

replace land_iso2="EUROPA" if land_id==100800
replace land_str="Kontinent: Europa" if land_id==100800	

replace land_iso2="AFRIKA" if land_id==100810
replace land_str="Kontinent: Afrika" if land_id==100810

replace land_iso2="ASIEN" if land_id==100820
replace land_str="Kontinent: Asien" if land_id==100820

replace land_iso2="MIT-OST" if land_id==100824
replace land_str="Kontinent: Mittlerer Osten" if land_id==100824

replace land_iso2="NORDAMERIKA" if land_id==100844
replace land_str="Kontinent: Nordamerika" if land_id==100844

replace land_iso2="LATEINAMERIKA" if land_id==100848
replace land_str="Kontinent: Lateinamerika" if land_id==100848

replace land_iso2="OZEANIEN" if land_id==100870
replace land_str="Kontinent: Ozeanien" if land_id==100870

sort handel_typ jahr monat land_id
order handel_typ jahr monat land_id land_str land_iso2 handel*
compress
save "${root}\temp\1997_2020_Mimporte_Mexporte_HP.dta", replace

*APPEND TRADE DATA BY WARENART
clear
append using "${root}\temp\raw_1997_2020_Mexporte_WA.dta"
generate handel_typ="E"
append using "${root}\temp\raw_1997_2020_Mimporte_WA.dta"
replace handel_typ="I" if handel_typ==""

foreach var in w v wa va ws vs wt vt {
	format `var' %16.2f
}

rename periode monat
rename wgruppe waren_art_id

rename w handel_chf
rename wa handel_chf_a
rename ws handel_chf_s
rename wt handel_chf_t

rename v handel_kg
rename va handel_kg_a
rename vs handel_kg_s
rename vt handel_kg_t

rename p preis_index
rename pa preis_index_a
rename ps preis_index_s
rename pt preis_index_t

*Merge Waren Labels
merge m:1 waren_art_id using "${root}\temp\codes_warenart.dta"
drop if _merge==2 /*Kategorien 13 Edelmetalle & 14 Kunstgegenstände nicht vorhanden*/
drop _merge

gen l=length(waren_art_id)
keep if l<=4 
drop l

sort handel_typ jahr monat waren_art_id
order handel_typ jahr monat waren_art_id waren_art_str handel* preis*
compress
save "${root}\temp\1997_2020_Mimporte_Mexporte_WA.dta", replace


********************************************************************************
*2. Generate Additional Variables
********************************************************************************

use "${root}\temp\1997_2020_Mimporte_Mexporte_HP.dta", replace

*Volumen in Mia / Tonnen
foreach var in handel_chf handel_chf_a handel_chf_s handel_chf_t {
	gen `var'_mio=`var'/(1000*1000)
	gen `var'_mia=`var'/(1000*1000*1000)
}

gen SAMPLE=21
replace SAMPLE=22 if land_id>1000
replace SAMPLE=31 if inlist(land_id, 100302)
replace SAMPLE=33 if inlist(land_id, 100305)

save "${root}\temp\1997_2020_Mimporte_Mexporte_HP_SAMPLE.dta", replace


use "${root}\temp\1997_2020_Mimporte_Mexporte_WA.dta", replace

*Volumen in Mia / Tonnen
foreach var in handel_chf handel_chf_a handel_chf_s handel_chf_t {
	gen `var'_mio=`var'/(1000*1000)
	gen `var'_mia=`var'/(1000*1000*1000)
}

foreach var in "" "_a" "_s" "_t"  {
	gen handel_tonnen`var'=handel_kg`var'/(1000)
}


*Variablen für aggregierte Warenarten
*************************************

*KAT12: Hauptkategorien gemäss FCA
destring waren_art_id, gen(waren_art_kat12)
replace waren_art_kat12=. if !inlist(waren_art_kat12, 1,2,3,4,5,6,7,8,9,10,11,12)

label define kat12																///
1 "(1) Land- & Forstwirtschaftliche Produkte"									///
2 "(2) Energieträger"															///
3 "(3) Textilien"																///
4 "(4) Papierwaren & grafische Erzeugnisse"										///
5 "(5) Leder, Kautschuk, Kunststoffe"											///
6 "(6) Produkte d. Chemischen/Pharmazeutischen Industrie"						///
7 "(7) Erden / Steine"															///
8 "(8) Metalle"																	///
9 "(9) Maschinen, Elektronik, Apparate"											///
10 "(10) Fahrzeuge"																///
11 "(11) Präzisionsinstrumente, Uhren, Schmuck"									///
12 "(12) Verschiedenes (Möbel, Sportgeräte, Instrumente usw.)"
label values waren_art_kat12 kat12

*KAT 6: Zusammengefasste Hauptkategorien 															
gen waren_art_kat6=.

replace waren_art_kat6=610 if inlist(waren_art_kat12, 1) 
replace waren_art_kat6=620 if inlist(waren_art_kat12, 2)
replace waren_art_kat6=630 if inlist(waren_art_kat12, 3, 4, 12) | inlist(waren_art_id, "11.3")
replace waren_art_kat6=640 if inlist(waren_art_kat12, 5, 7)
replace waren_art_kat6=650 if inlist(waren_art_kat12, 6)
replace waren_art_kat6=660 if inlist(waren_art_kat12, 8, 9, 10) | inlist(waren_art_id, "11.1", "11.2")

label define kat6																///
610 "(610) Land- & Forstwirtschaftliche Produkte"								///
620 "(620) Energieträger"														///
630 "(630) Leichtindustrie: Textilien, Papierwaren, Schmuck, Verschiedenes"		///
640 "(640) Rohstoffe (exkl. Metall): Leder, Kunstoffe, Kautschuk, Steine"		///
650 "(650) Chemische/Pharmazeutische Produkte"									///
660 "(660) Metall & Industrie: Metall, Maschinen, Elektronik, Fahrzeuge, Präzisionsinstrumente"						
label values waren_art_kat6 kat6

*KAT 5: Zusammengefasste Hauptkategorien
gen waren_art_kat5=.

replace waren_art_kat5=510 if inlist(waren_art_kat12, 1)
replace waren_art_kat5=520 if inlist(waren_art_kat12, 2)
replace waren_art_kat5=530 if inlist(waren_art_kat12, 3, 4, 5, 7, 12) | inlist(waren_art_id, "11.3")
replace waren_art_kat5=540 if inlist(waren_art_kat12, 6)
replace waren_art_kat5=550 if inlist(waren_art_kat12, 8, 9, 10) | inlist(waren_art_id, "11.1", "11.2")
label define kat5																///
510 "(510) Land- & Forstwirtschaftliche Produkte"								///
520 "(520) Energieträger"														///
530 "(530) Leichtindustrie & Rohstoffe (exkl. Metall): Textilien, Papierwaren, Schmuck, Leder, Steine"	///					
540 "(550) Chemischen/Pharmazeutische Produkte"									///
550 "(550) Metall & Industrie: Metall, Maschinen, Elektronik, Fahrzeuge, Präzisionsinstrumente"																	
label values waren_art_kat5 kat5

*KAT 4: Zusammengefasste Hauptkategorien
gen waren_art_kat4=.

replace waren_art_kat4=410 if inlist(waren_art_kat12, 1, 3, 4, 5, 7, 12) | inlist(waren_art_id, "11.3")
replace waren_art_kat4=420 if inlist(waren_art_kat12, 2)
replace waren_art_kat4=430 if inlist(waren_art_kat12, 6)
replace waren_art_kat4=440 if inlist(waren_art_kat12, 8, 9, 10) | inlist(waren_art_id, "11.1", "11.2")

label define kat4																///
410 "(410) Verschiedenes"														///
420 "(420) Energieträger"														///
430 "(430) Chemischen/Pharmazeutische Produkte"									///
440 "(440) Metall & Industrie: Metall, Maschinen, Elektronik, Fahrzeuge, Präzisionsinstrumente"													
label values waren_art_kat4 kat4

*KAT 3: Zusammengefasste Hauptkategorien
gen waren_art_kat3=.

replace waren_art_kat3=310 if inlist(waren_art_kat12, 1, 2, 3, 4, 5, 7, 12) | inlist(waren_art_id, "11.3")
replace waren_art_kat3=320 if inlist(waren_art_kat12, 6)
replace waren_art_kat3=330 if inlist(waren_art_kat12, 8, 9, 10) | inlist(waren_art_id, "11.1", "11.2")

label define kat3																///
310 "(310) Total excl. Chemie sowie Metall & Industrie"							///
320 "(320) Chemischen/Pharmazeutische Produkte"									///
330 "(330) Metall & Industrie: Metall, Maschinen, Elektronik, Fahrzeuge, Präzisionsinstrumente"													
label values waren_art_kat3 kat3

*KAT 2: Zusammengefasste Hauptkategorien
gen waren_art_kat2=.

replace waren_art_kat2=210 if inlist(waren_art_kat12, 1, 3, 4, 12, 9, 10, 11, 5, 7, 8, 2)
replace waren_art_kat2=220 if inlist(waren_art_kat12, 6)

label define kat2																///
210 "(210) Total excl. Chemie/Pharmazie"										///
220 "(220) Chemischen/Pharmazeutische Produkte"													
label values waren_art_kat2 kat2


*Aggregierte Statistiken
************************
gen SAMPLE=1

*Aggregierte Statistiken: Total
replace waren_art_id="9999" if waren_art_id=="0"
replace waren_art_str="total" if waren_art_id=="9999"
replace SAMPLE=99 if waren_art_id=="9999"


*Aggregierte Statistiken: Nach Warenart KAT12
replace waren_art_id="8012" if waren_art_kat12!=. 
replace waren_art_str="12 Kategorien (FCA)" if waren_art_id=="8012"
replace SAMPLE=51 if waren_art_id=="8012"

*Aggregierte Statistiken: Nach Warenart KAT6
preserve 
drop if waren_art_kat6==.
collapse (sum) 																	///
handel_chf_mio handel_chf_mia handel_chf_*_mio handel_chf_*_mia handel_tonnen_*, ///
by(jahr monat handel_typ waren_art_kat6)								

gen waren_art_id="8006" 
gen waren_art_str="6 Kategorien (own)" 
gen land_id=9999
gen land_str="world"
gen land_iso2="world"
gen SAMPLE=56
saveold "${root}\temp\kat6_trade_M_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken: Nach Warenart KAT5
preserve 
drop if waren_art_kat5==.
collapse (sum) 																	///
handel_chf_mio handel_chf_mia handel_chf_*_mio handel_chf_*_mia handel_tonnen_*, ///
by(jahr monat handel_typ waren_art_kat5)								

gen waren_art_id="8005" 
gen waren_art_str="5 Kategorien (own)" 
gen land_id=9999
gen land_str="world"
gen land_iso2="world"
gen SAMPLE=55
saveold "${root}\temp\kat5_trade_M_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken: Nach Warenart KAT4
preserve 
drop if waren_art_kat4==.
collapse (sum) 																	///
handel_chf_mio handel_chf_mia handel_chf_*_mio handel_chf_*_mia handel_tonnen_*, ///
by(jahr monat handel_typ waren_art_kat4)		
gen waren_art_id="8004" 
gen waren_art_str="4 Kategorien (own)" 
gen land_id=9999
gen land_str="world"
gen land_iso2="world"
gen SAMPLE=54
saveold "${root}\temp\kat4_trade_M_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken: Nach Warenart KAT3
preserve 
drop if waren_art_kat3==.
collapse (sum) 																	///
handel_chf_mio handel_chf_mia handel_chf_*_mio handel_chf_*_mia handel_tonnen_*, ///
by(jahr monat handel_typ waren_art_kat3)										

gen waren_art_id="8003" 
gen waren_art_str="3 Kategorien (own)" 
gen land_id=9999
gen land_str="world"
gen land_iso2="world"
gen SAMPLE=53
saveold "${root}\temp\kat3_trade_M_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken: Nach Warenart KAT2
preserve 
drop if waren_art_kat2==.
collapse (sum) 																	///
handel_chf_mio handel_chf_mia handel_chf_*_mio handel_chf_*_mia handel_tonnen_*, ///
by(jahr monat handel_typ waren_art_kat2)									

gen waren_art_id="8002" 
gen waren_art_str="2 Kategorien (own)" 
gen land_id=9999
gen land_str="world"
gen land_iso2="world"
gen SAMPLE=52
saveold "${root}\temp\kat2_trade_M_temp.dta", replace version(13)
restore 

*Append aggregierte Statistiken
append using "${root}\temp\1997_2020_Mimporte_Mexporte_HP_SAMPLE.dta"
append using "${root}\temp\kat6_trade_M_temp.dta"
append using "${root}\temp\kat5_trade_M_temp.dta"
append using "${root}\temp\kat4_trade_M_temp.dta"
append using "${root}\temp\kat3_trade_M_temp.dta"
append using "${root}\temp\kat2_trade_M_temp.dta"

label define smple																///
1 "(1) Rohdaten -- Monat, Warenart"												/// 
21 "(21) Ländertotal -- Monat, Land"											///
22 "(22) Kontinenttotal -- Monat, Kontinent"									///
31 "(31) EU-Total (inkl. GB) -- Monat, EU"										///
32 "(32) EU+EFTA-Total (inkl. GB) -- Monat, EU/EFTA vs. !EU/EFTA"				///
33 "(33) Eurozone-Total -- Monat, Eurozone"										///
51 "(51) Kat. 12: Warenart-Total -- Monat, Handelvolumen, Kat12"				///
52 "(52) Kat. 2: Warenart-Total -- Monat, Handelvolumen, Kat2"					///
53 "(53) Kat. 3: Warenart-Total -- Monat, Handelvolumen, Kat3"					///
54 "(54) Kat. 4: Warenart-Total -- Monat, Handelvolumen, Kat4"					///
55 "(55) Kat. 5: Warenart-Total -- Monat, Handelvolumen, Kat5"					///
56 "(56) Kat. 6: Warenart-Total -- Monat, Handelvolumen, Kat6"					///
99 "(99) Welt-Total -- Monat, Handelsvolumen"
label values SAMPLE smple

replace waren_art_id="9999" if waren_art_id==""
replace waren_art_str="total" if waren_art_id=="9999"
replace land_id=9999 if land_id==.
replace land_iso2="world" if land_id==9999
replace land_str="world" if land_id==9999

foreach var of varlist _all {
	label var `var' ""
}

gen datum=ym(jahr, monat)
format datum %tmMCY


label var handel_chf_mio "Raw Data"
label var handel_chf_mia "Raw Data"
label var handel_chf_a_mio "Arbeitstagbereinigt"
label var handel_chf_a_mia "Arbeitstagbereinigt"
label var handel_chf_s_mio "Saisonbereinigt"
label var handel_chf_s_mia "Saisonbereinigt"
label var handel_chf_t_mio "Trend"
label var handel_chf_t_mia "Trend"

label var handel_tonnen "Raw Data"
label var handel_tonnen_a "Arbeitstagbereinigt"
label var handel_tonnen_s "Saisonbereinigt"
label var handel_tonnen_t "Trend"

rename handel_chf_*_mio handel_chf_mio_*
rename handel_chf_*_mia handel_chf_mia_*

drop handel_chf handel_kg handel_chf_a handel_kg_a handel_chf_s handel_kg_s handel_chf_t handel_kg_t

sort SAMPLE jahr monat datum handel_typ waren_art_id land_id  land_str

order SAMPLE jahr monat datum handel_typ 										///
waren_art_id waren_art_str land_id land_str land_iso2							///
handel_chf_mio handel_chf_mia handel_chf_mio_a handel_chf_mia_a 				///
handel_chf_mio_s handel_chf_mia_s handel_chf_mio_t handel_chf_mia_t				///
handel_tonnen handel_tonnen_a handel_tonnen_s handel_tonnen_t					///
preis_index preis_index_a preis_index_s preis_index_t							///
waren_art_kat12 waren_art_kat6 waren_art_kat5 waren_art_kat4 waren_art_kat3 waren_art_kat2					

compress
saveold "${root}\workfiles\trade_2002_2020_M_analysis.dta", replace version(13)

*wide format
use "${root}\workfiles\trade_2002_2020_M_analysis.dta", clear

gen var_name=""
replace var_name="land_iso2" if SAMPLE==1
replace var_name="land_iso2" if SAMPLE==21
replace var_name="land_iso2" if SAMPLE==22
replace var_name="land_iso2" if SAMPLE==31
replace var_name="land_iso2" if SAMPLE==32
replace var_name="land_iso2" if SAMPLE==33
replace var_name="waren_art_kat12" if SAMPLE==51
replace var_name="waren_art_kat2" if SAMPLE==52
replace var_name="waren_art_kat3" if SAMPLE==53
replace var_name="waren_art_kat4" if SAMPLE==54
replace var_name="waren_art_kat5" if SAMPLE==55
replace var_name="waren_art_kat6" if SAMPLE==56
replace var_name="land_iso2" if SAMPLE==99


levelsof SAMPLE, local(sample)
foreach num of local sample {
	
	preserve 
	keep if SAMPLE==`num'
	
	levelsof var_name, local(add_var) clean
	di in red "`add_var'"
	
	reshape wide handel_chf_mio handel_chf_mia handel_chf_mio_a handel_chf_mia_a 	///
	handel_chf_mio_s handel_chf_mia_s handel_chf_mio_t handel_chf_mia_t				///
	handel_tonnen handel_tonnen_a handel_tonnen_s handel_tonnen_t					///
	preis_index preis_index_a preis_index_s preis_index_t,							///	
	i(SAMPLE jahr monat datum  waren_art_id land_id `add_var')						///
	j(handel_typ) string

	rename handel_chf_mioE export_chf_mio
	rename handel_chf_miaE export_chf_mia
	rename handel_chf_mio_*E export_chf_mio_*
	rename handel_chf_mia_*E export_chf_mia_*
	
	rename handel_tonnenE export_tonnen
	rename handel_tonnen_*E export_tonnen_*
	
	rename handel_chf_mioI import_chf_mio
	rename handel_chf_miaI import_chf_mia
	rename handel_chf_mio_*I import_chf_mio_*
	rename handel_chf_mia_*I import_chf_mia_*
	
	rename handel_tonnenI import_tonnen
	rename handel_tonnen_*I import_tonnen_*
	
	rename preis_indexI preis_index_import
	rename preis_indexE preis_index_export
	
	rename preis_index_*I preis_index_import_*
	rename preis_index_*E preis_index_export_*

	foreach b in  "" "_a" "_s" "_t" {
		foreach v in  chf_mio chf_mia tonnen {
			foreach t in export import {
				replace `t'_`v'`b'=0 if `t'_`v'`b'==.
				format `t'_`v'`b' %14.2f
			} 
		}
	}
	
	compress
	saveold "${root}\temp\trade_2002_2020_M_wide_`num'.dta", replace version(13)
	restore 
}


clear
foreach num of local sample {
	append using "${root}\temp\trade_2002_2020_M_wide_`num'.dta"
}

drop var_name

foreach var of varlist _all {
	label var `var' ""
}

sort SAMPLE land_id waren_art_id jahr monat 					
				
order SAMPLE jahr monat datum  waren_art_id waren_art_str land_id land_str land_iso2	///
export_chf_mio export_chf_mia export_chf_mio_a export_chf_mia_a 				///
export_chf_mio_s export_chf_mia_s export_chf_mio_t export_chf_mia_t 			///
export_tonnen export_tonnen_a export_tonnen_s export_tonnen_t 					///
import_chf_mio import_chf_mia import_chf_mio_a import_chf_mia_a 				///
import_chf_mio_s import_chf_mia_s import_chf_mio_t import_chf_mia_t 			///
import_tonnen import_tonnen_a import_tonnen_s import_tonnen_t 					///
preis_index_export preis_index_export_a preis_index_export_s preis_index_export_t ///
preis_index_import preis_index_import_a preis_index_import_s preis_index_import_t ///
waren_art_kat12 waren_art_kat6 waren_art_kat5 waren_art_kat4 waren_art_kat3 waren_art_kat2

compress  
saveold "${root}\workfiles\trade_2002_2020_M_analysis_wide.dta", replace version(13)

